package com.mspbots.api.service.impl;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.mspbots.api.service.TeamsUserService;
import com.mspbots.cw.request.TenantTeamsUserDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;

/**
 * com.mspbots.api.service.impl.TenantTeamsUserServiceImpl
 *
 * @author Jun Zhou
 * @date 12:18 2019/7/3
 **/
@Deprecated
@Slf4j
@Service
public class TeamsUserServiceImpl extends BaseGenericService implements TeamsUserService {


    @Override
    public List<TenantTeamsUserDTO> addBatch(List<TenantTeamsUserDTO> tenantUsers) {
        Mono<JsonNode> resultMono = this.apiClient.post("/teams/user/add-batch", tenantUsers);
        JsonNode result = resultMono.block();
        tenantUsers = this.objectMapper.convertValue(result, new TypeReference<List<TenantTeamsUserDTO>>() {
        });
        return tenantUsers;
    }

    @Override
    public List<TenantTeamsUserDTO> selectByTenant(Long tenantId) {
        Mono<JsonNode> resultMono = this.apiClient.get("/teams/user/" + tenantId);
        JsonNode result = resultMono.block();
        return this.objectMapper.convertValue(result, new TypeReference<List<TenantTeamsUserDTO>>() {
        });
    }

    @Override
    public List<TenantTeamsUserDTO> selectList(Map<String, Object> params) {
        Mono<JsonNode> resultMono = this.apiClient.get("/teams/user/list", params);
        JsonNode result = resultMono.block();
        return this.objectMapper.convertValue(result, new TypeReference<List<TenantTeamsUserDTO>>() {
        });
    }

    @Override
    public TenantTeamsUserDTO insert(TenantTeamsUserDTO tenantTeamsUserDTO) {
        Mono<JsonNode> resultMono = this.apiClient.post("/teams/user/", tenantTeamsUserDTO);
        JsonNode result = resultMono.block();
        return this.objectMapper.convertValue(result, new TypeReference<TenantTeamsUserDTO>() {
        });
    }
}
